const {
	userCollection
} = require('../../common/constants');
const {
	ERROR
} = require('../../common/error');

module.exports = async function() {
	const {
		uid
	} = this.authInfo;

	const defaultMember = {
		// 0 未开通 1 生效中 2 已过期
		status: 0,
		// 订阅时间
		subscribe_date: "",
		// 套餐类型
		subscribe_type: 0,
		// 过期时间
		expiration_date: ""
	}

	const getUserRes = await userCollection.doc(uid).get();
	const userRecord = getUserRes && getUserRes.data && getUserRes.data[0];

	if (!userRecord) {
		throw {
			errCode: ERROR.ACCOUNT_NOT_EXISTS
		}
	}

	return {
		errCode: 0,
		member: userRecord.member ? userRecord.member : defaultMember
	}
}